var express = require('express');
var router = express.Router();
var pool = require('../mysql/index');

/* GET users listing. */
/**
 * 接收所有请求方式
 */
router.all('/', function(req, res, next) {
	if(req.method == 'GET'){
		res.send('respond with a resource');
	}else {
		res.send('please use get request');
	}
	
});
/**
 * 接收get请求
 */
router.get('/info',(req,res,next) => {
	res.send('/users/infos');
})
/**
 * 接收post请求
 *  username 不是 为空的时候 debugger
 */
router.post('/addUser', (req, res, next) => {
	let username = req.query.username;
	if(username != undefined){
		pool.query(`select * from userinfo where userId = "${username}"`,null).then((rows)=>{
			res.json(rows);
		}).catch(err=>{
			console.log(err)
		})
	}else {
		res.send("没有数据")
	}
})

module.exports = router;
